from django.contrib import admin

from .models import BookInfo, HeroInfo

class HeroInfoInline(admin.TabularInline):
    """关联展示"""
    model = HeroInfo
    extra = 2  # 额外给几个新增输入框


class BookInfoAdmin(admin.ModelAdmin):
    """book模型站点管理类"""
    list_per_page = 2  # 指定每页显示多少条数据
    actions_on_bottom = True
    list_display = ['id', 'btitle', 'bpub_date', 'bread', 'bcomment', 'bread_fo']

    # fields = ['btitle', 'bpub_date']  # 控制编辑界面展示那些字段
    fieldsets = [
        ['基本', {'fields': ['btitle', 'bpub_date', 'image']}],
        ['高级', {'fields': ['bread', 'bcomment', 'is_delete'], 'classes': ['collapse']}],
        ['高高级', {'fields': []}]
    ]

    inlines = [HeroInfoInline]  # 在编辑页面一查多的关联编辑
    pass

@admin.register(HeroInfo)
class HeroInfoAdmin(admin.ModelAdmin):
    """hero模型站点管理类"""

    list_display = ['id', 'hname', 'hgender', 'hcomment', 'hbook']
    list_filter = ['hgender', 'hbook']
    search_fields = ['hname', 'id']
    pass

# Register your models here.
admin.site.register(BookInfo, BookInfoAdmin)
# admin.site.register(HeroInfo, HeroInfoAdmin)


# 以下三个配置是来修改admin首页标题
admin.site.site_header = '传智书城'  # 首页头部标题
admin.site.site_title = '传智书城MIS'  # 标签页标题
admin.site.index_title = '欢迎使用传智书城MIS'  # 首页欢迎语